<?php $method = $_GET['method'];
switch ($method) {
    case 'getUserInfo':
        $token = $_GET['token'];
        echo getUserInfo($token);
        break;
    case 'getNewPeriod2':
        echo getNewPeriod2();
        break;
    case 'getLotteryResultList':
        echo getLotteryResultList();
        break;
    case 'doBet':
        $token = $_GET['token'];
        $data = $_GET['data'];
        $data = json_decode($data, 1);
        echo doBet($token, $data);
        break;
    case 'saveContent':
        $content = $_GET['content'];
        $file = fopen("utils/content.txt", "w");
        fwrite($file, $content);
        break;
    case 'readContent':
        $file = fopen("utils/content.txt", "r");
        $content = fread($file, filesize("utils/content.txt"));
        echo json_encode(array("code" => 200, "serverCode" => getSystemUUID(), "a" => "77180d2661d15029ce56a57ad79b20ca", "v" => '1.0.3', "content" => $content));
        break;
    default:
        break;
}

function getUserInfo($token) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt_array($curl, array(CURLOPT_URL => 'https://xisose06.xcvb9323viok.com:59789/accInfo/getAccount.do', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array("Cookie: ${token}")));
    $response = curl_exec($curl);
    curl_close($curl);
    return $response;
}

function getNewPeriod2() {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    $timestamp = time();
    curl_setopt_array($curl, array(CURLOPT_URL => "https://xisose06.xcvb9323viok.com:59789/lotData/getNewPeriod2.do?code=AZXYW168&_=${$timestamp}", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array('Cookie: SESSION=311ca243-f38f-41e5-af1e-5d3624e57c74')));
    $response = curl_exec($curl);
    curl_close($curl);
    echo $response;
}

function getLotteryResultList() {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    $timestamp = time();
    curl_setopt_array($curl, array(CURLOPT_URL => "https://xisose06.xcvb9323viok.com:59789/lotData/getLotteryResultList.do?code=AZXYW168&version=2&pageSize=20&pageNumber=1&_=${$timestamp}", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array('Cookie: SESSION=311ca243-f38f-41e5-af1e-5d3624e57c74')));
    $response = curl_exec($curl);
    curl_close($curl);
    echo $response;
}

function doBet($token, $data) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt_array($curl, array(CURLOPT_URL => 'https://xisose06.xcvb9323viok.com:59789/credit/doBet.do', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('code' => $data['code'], 'orderList' => json_encode($data['orderList']), 'kickback' => '0', 'qiHao' => $data['qiHao']), CURLOPT_HTTPHEADER => array("Cookie: ${token}")));
    $response = curl_exec($curl);
    curl_close($curl);
    echo $response;
}

function getSystemUUID() {
    $os = php_uname('s');
    $uuid = '';
    if ($os === 'Darwin') {
        $output = shell_exec('system_profiler SPHardwareDataType | grep "UUID"');
        preg_match('/[0-9A-F]{8}(?:-[0-9A-F]{4}){3}-[0-9A-F]{12}/i', $output, $matches);
        $uuid = isset($matches[0]) ? $matches[0] : '';
    }
    elseif(strtoupper(substr($os, 0, 5)) === 'Linux') {
        $uuid = trim(file_get_contents('/sys/class/dmi/id/product_uuid'));
    }
    elseif(strtoupper(substr($os, 0, 3)) === 'WIN') {
        $output = shell_exec('wmic csproduct get UUID');
        $uuid = explode("\n", trim($output))[1];
    }
    return $uuid;
}

function getFileMd5($filePath) {
    return md5_file($filePath);
}